﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace SwormTests.IUD
{
    public class with_no_pk : TestBase
    {
        public with_no_pk(DbToTest db) : base(db) { }

        class no_pk
        {
            public string col1 { get; set; }
        }

        [Test]
        [ExpectedException(typeof(Sworm.MissingPrimaryKeyException))]
        public void cannot_update()
        {
            DB.Update(new no_pk());
        }

        [Test]
        [ExpectedException(typeof(Sworm.MissingPrimaryKeyException))]
        public void cannot_delete()
        {
            DB.Delete(new no_pk());
        }

        [Test]
        public void can_insert()
        {
            int rowsAffected = DB.Insert(new no_pk() { col1 = "hello" });
            Assert.AreEqual(1, rowsAffected);

            var record = DB.Query.Simple<no_pk>().Single();
            Assert.AreEqual("hello", record.col1);
        }
    }
}
